package cn.yup.service.impl;

import cn.yup.domain.WorkJob;
import cn.yup.mapper.WorkJobMapper;
import cn.yup.service.IWorkJobService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service   // 表示把该类创建对象交给Spring 管理  @controller
public class WorkJobServiceImpl implements IWorkJobService {


    @Autowired //  表示 从spring 容器中 获取 WorkJobMapper 对象 赋给 workJobMapper 这个变量
    private WorkJobMapper workJobMapper  ;


    @Override
    public PageInfo findAll(String name) {
        // PageHelper 插件处理分页
        // 当前页的数据
       List<WorkJob> workJobs =  workJobMapper.findAll(name);

        return  new  PageInfo(workJobs);
    }

    @Override
    public void deleteById(Long id) {
        workJobMapper.deleteById(id) ;
    }

    @Override
    public void saveOrUpdate(WorkJob workJob) {
        if (workJob.getId() != null) {
            workJobMapper.updateById(workJob);
        }
        else {

            workJobMapper.save(workJob);
        }
    }

    @Override
    public WorkJob findById(Long id) {
        return workJobMapper.findById(id);
    }

    @Override
    public List<WorkJob> listAll() {
        return workJobMapper.selectAll();
    }

    @Override
    public WorkJob getWorkJobByName(String name) {
        return workJobMapper.findByName(name);
    }


}
